
/*
 *   File name    : Lock.h
 *   Version      : 1.0.0
 *   Description  : Lock for log file 
 *   Author       : zxliu
 *   Created on   : 20120911
 *   Modified list: 
 */

#ifndef LOCK_H
#define LOCK_H

#include <pthread.h>

namespace SERVERTOOL
{
    class Lock
    {
    public:
        Lock();
        ~Lock();
        void lock();
        void unlock();

    private:
        pthread_mutex_t  m_section;
    };

    /*
     * The constructor.
     */
    inline Lock::Lock()
    {
        pthread_mutex_init(&m_section, NULL);
    }

    /*
     * The destructor.
     */
    inline Lock::~Lock()
    {
        pthread_mutex_destroy(&m_section);
    }

    /*
     * The member function lock locks a region.
     */
    inline void Lock::lock()
    {
        pthread_mutex_lock(&m_section);
    }

    /*
     * the member function unlock unlocks a region.
     */
    inline void Lock::unlock()
    {
        pthread_mutex_unlock(&m_section);
    }
}

#endif

